#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"
#include "unittests.h"

int run_tests1() {
    int player1 = 0;
    int handCount = 5;
    int coppers[MAX_HAND];
    for (int i = 0; i < MAX_HAND; i++) {
        coppers[i] = copper;
    }

    struct gameState state;
    memset(&state, 0, sizeof(struct gameState)); // clear the game state
    int kingdom_cards[10] = {adventurer, council_room, feast, gardens, mine,
        remodel, smithy, village, baron, great_hall};

    initializeGame(2, kingdom_cards, 1, &state); // initialize a new game
    state.handCount[player1] = handCount; // set the number of cards on hand
    memcpy(state.hand[player1], coppers, sizeof(int) * handCount); // set all the cards to copper

    printf("Testing gainCard()\n");


    int supplyCount = state.supplyCount[silver];
    // Add a silver to player1 hand
    assert(gainCard(silver, &state, 2, player1) == 0);
    // Check that our silver supply went down
    assert(state.supplyCount[silver] == (supplyCount - 1));
    // Check the card we just drew is silver (-1 is there because we just drew)
    assert(state.hand[player1][state.handCount[player1] - 1] == silver);
    printf("gainCard(): draw effect passed!\n");

    // Reset
    memset(&state, 0, sizeof(struct gameState)); // clear the game state
    initializeGame(2, kingdom_cards, 1, &state); // initialize a new game
    state.handCount[player1] = handCount; // set the number of cards on hand
    memcpy(state.hand[player1], coppers, sizeof(int) * handCount); // set all the cards to copper

    supplyCount = state.supplyCount[silver];
    // Add a silver to deck
    assert(gainCard(silver, &state, 1, player1) == 0);
    // Check our supply count has gone down
    assert(state.supplyCount[silver] == (supplyCount - 1));
    // Check that it was added to the deck
    assert(state.deck[player1][state.deckCount[player1] - 1] == silver);
    printf("gainCard(): add to deck effect passed!\n");


    // Reset
    memset(&state, 0, sizeof(struct gameState)); // clear the game state
    initializeGame(2, kingdom_cards, 1, &state); // initialize a new game
    state.handCount[player1] = handCount; // set the number of cards on hand
    memcpy(state.hand[player1], coppers, sizeof(int) * handCount); // set all the cards to copper


    supplyCount = state.supplyCount[silver];
    // Add a silver to discard
    assert(gainCard(silver, &state, 0, player1) == 0);
    // Check our supply count has gone down
    assert(state.supplyCount[silver] == (supplyCount - 1));
    // Check that it was added to the discard
    assert(state.discard[player1][state.discardCount[player1] - 1] == silver);
    printf("gainCard(): add to discard effect passed!\n");

    printf("\n");

    return 0;
}
